﻿<!DOCTYPE html>
<html>
<head>
	<title>修改密码</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="styles/login.css"/>
	<script type="text/javascript" 	src="scripts/common/jquery.min.js"></script> <!-- 引入jquery框架 -->
	<script type="text/javascript" src="scripts/base.js"></script> <!-- 引入项目的访问路径 -->
	<script type="text/javascript" src="scripts/cookie_util.js"></script><!-- 引入cookie -->
	<script type="text/javascript" src="scripts/login.js"></script><!-- 引入登录和注册的处理 -->
	<script type="text/javascript">
	//页面加载	
		$(function () {
			//返回
			$("#back").click(function () {
				window.location.href="edit.html";
			});
			//确定修改密码
			$("#changePassword").click(function(){
				//获取参数
				//获取此时cookie中的userId
				var userName=getCookie("userName");
				var last_password=$("#last_password").val().trim();//获取输入的原密码
				var new_password=$("#new_password").val().trim();//获取输入的新密码
				var final_password=$("#final_password").val().trim();//获取输入的最后的密码
				//检查数据格式
				var ok=true;
				if(last_password==""){
					$("#warning_1 span").html("原密码不能为空");
					$("#warning_1").show();//显示出来
					ok=false;
				}
				if(new_password==""){
					$("#warning_2 span").html("新密码不能为空");
					$("#warning_2").show();//显示出来
					ok=false;
				}else if(new_password.length>0&&new_password.length<6){
					$("#warning_2 span").html("新密码不能小于小于6位");
					$("#warning_2").show();//显示出来
					ok=false;
				}
				
				if(final_password==""){
					$("#warning_3 span").html("确认新密码不能为空");
					$("#warning_3").show();//显示出来
					ok=false;
				}else if(final_password!=new_password){
					$("#warning_3 span").html("输入密码不一致");
					$("#warning_3").show();//显示出来
					ok=false;
				}
				//数据校验通过
				if(ok){
					$.ajax({
						url:base_path+"/user/change.do",
						type:"post",
						data:{"userName":userName,"last_password":last_password,"final_password":final_password},
						dataType:"json",
						success:function(result){
							if(result.status==0){//成功
								alert(result.msg);
								//转向登录界面
								window.location.href="log_in.html";
							}else if(result.status==1){//原密码不正确
								$("#warning_1 span").html(result.msg);
								$("#warning_1").show();
							}else if(result.status==2){//原密码与新密码一致
								$("#warning_2 span").html(result.msg);
								$("#warning_2").show();
							}
						},
						error:function(){
							alert("注册异常");
						}
					});
				}
				
			});
		});
	</script>
</head>
	<body>
		<div class="global">
			<div class="sig sig_in" tabindex='4' id='zc'>
				<dl>
					<dt>
						<div class='header'>
							<h3>修改密码</h3>
						</div>
					</dt>
					<dt></dt>
					<dt>
						<div class='letter'>
							原密码:&nbsp;<input type="password" name="" id="last_password" tabindex='1'/>
							<div class='warning' id='warning_1'><span></span></div>
						</div>
					</dt>
					<dt>
						<div class='letter'>
							新密码:&nbsp;<input type="password" name="" id="new_password" tabindex='2'/>
							<div class='warning' id='warning_2'><span></span></div>
						</div>
					</dt>
					<dt>
						<div class='password'>
							确认新密码:&nbsp;<input type="password" name="" id="final_password" tabindex='3'/>
							<div class='warning' id='warning_3'><span></span></div>
						</div>
					</dt>
					<dt>
						<div>
							<input type="button" name="" id="changePassword" value='&nbsp;确&nbsp;定&nbsp;' tabindex='4'/>
							<input type="button" name="" id="back" value='&nbsp;关&nbsp;闭&nbsp;' tabindex='5'/>
						</div>
					</dt>
				</dl>
			</div>
		</div>
		<script type="text/javascript">
			function get(e){
				return document.getElementById(e);
			}
			window.onload=function(){
				var t =setTimeout("get('zc').style.visibility='visible'",800);
				get('last_password').onfocus=function(){
					get('warning_1').style.display='none';
				}
				get('new_password').onfocus=function(){
					get('warning_2').style.display='none';
				}
				get('final_password').onfocus=function(){
					get('warning_3').style.display='none';
				}
			}
		</script>
	</body>
</html>